import threading
import time
from venv import logger

from utils.constants import READ_INTERVAL


class Consumer(threading.Thread):

    def __init__(self, config, messageQueue):
        self.config = config
        self.messageQueue = messageQueue
        super().__init__()

    def run(self):
        while True:
            message_list = self.messageQueue.read_message()
            if message_list is not None:
                contents = []
                for message in message_list:
                    contents.append('\n'.join(message))
                if contents:
                    logger.info("receive: " + str(contents))
            # else:
            #     logger.info("no message list, let's wait")
            time.sleep(self.config[READ_INTERVAL])